﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>JavaScript/HTML格式化</title>

    <script src="../javascript/jquery/jquery.min.js" type="text/javascript"></script>

    <script src="../javascript/format/base.js" type="text/javascript"></script>

    <script src="../javascript/format/jsformat.js" type="text/javascript"></script>

    <script src="../javascript/format/jsformat2.js" type="text/javascript"></script>

    <script src="../javascript/format/htmlformat.js" type="text/javascript"></script>

    <script src="../javascript/common.js" type="text/javascript"></script>

    <script type="text/javascript">

        function do_js_beautify()
        {
            $("#beautify").attr("disabled", true);
            document.getElementById('beautify').disabled = true;
            js_source = document.getElementById('content').value.replace(/^\s+/, '');

            var lenStr = js_source.length;
            var tmp;
            var blockSise = 2000;
            var result = new StringBuffer();

            var tabsize = document.getElementById('tabsize').value;
            tabchar = ' ';
            if (tabsize == 1) tabchar = '\t';

            if (type.value == '2')
            {
                result.append(style_html(js_source, tabsize, tabchar, 80));
            }
            else
            {
                for (var i = 0; i * blockSise < lenStr; i++)
                {
                    var begin = i * blockSise;
                    var end = (i + 1) * blockSise;
                    tmp = js_source.substring(begin, end);
                    result.append(js_beautify(tmp, tabsize, tabchar));
                }
            }

            $("#content").val(result.toString());
            $("#beautify").attr("disabled", false);
            return false;
        }
        function pack_js(base64)
        {
            var input = $("#content").val();
            if ($.trim(input) == "") return;
            var packer = new Packer;
            if (base64)
            {
                var output = packer.pack(input, 1, 0);
            }
            else
            {
                var output = packer.pack(input, 0, 0);
            }
            document.getElementById('content').value = output;
        }
        function copy()
        {
            var Result = document.getElementById('content').value;
            if (document.getElementById('content').value != '')
            {
                window.clipboardData.setData("Text", Result);
                document.getElementById('content').select();
                window.alert('已复制成功！');
            }
        }
        function Empty()
        {
            document.getElementById('content').value = '';
            document.getElementById('content').select();
        }
        function GetFocus()
        {
            document.getElementById('content').focus();
        }

        function decode()
        {
            var input = $("#content").val();
            if (input.indexOf('eval') == 0)
            {
                eval("output=String" + input.slice(4));
                $("#content").val(output)
            }

            do_js_beautify();
        }
    </script>

</head>
<body>
    <div style="text-align: center" class="box">
        <div id="b_1">
            <!--<h1>
                <div class="titleft">
                    JavaScript/HTML格式化工具</div>
            </h1>-->
            <div class="box1">
                <div align="center" style="color: #006AAD; font-size: 16px; font-weight: bold;">
                    <h3>
                        JavaScript/HTML格式化</h3>
                </div>
                <div align="center" style="padding-top: 10px;">
                    <textarea id="content" name="content" style="width: 850px; border: 1px solid #c5e2f2;
                        height: 300px; overflow: visible;" cols="20" rows="20"></textarea>

                    <script type="text/javascript">                        setTimeout("GetFocus();", 10)</script>

                </div>
                <div style="padding: 7px 0px 0px 6px;">
                    <select name="tabsize" id="tabsize">
                        <option value="1">制表符缩进 </option>
                        <option value="2">2个空格缩进 </option>
                        <option value="4" selected="selected">4个空格缩进 </option>
                        <option value="8">8个空格缩进 </option>
                    </select>
                    <select name="tabsize" id="type">
                        <option value="1" selected="selected">Javascript</option>
                        <option value="2">Html </option>
                    </select>
                    <input class="but2" type="button" value="格式化" onclick="return do_js_beautify()" id="beautify" />
                    <input class="but2" type="button" value="普通压缩" onclick="pack_js(0)" />
                    <input class="but2" type="button" value="加密压缩" onclick="pack_js(1)" />
                    <input class="but2" type="button" value="解压缩" onclick="decode();" />
                    <input class="but2" type="button" value=" 复 制 " onclick="copy();" />
                    <input class="but2" type="button" value="清空结果" onclick="Empty();" />
                </div>
            </div>
        </div>
    </div>
</body>
</html>
